﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TestVibrator : MonoBehaviour {
    public Slider slider_amplitude;
    public Text text_sider_amplitude;
    private void Start()
    {
        OnValueChange_Sider_amplitude();
        OnValueChange_Sider_milliseconds();
    }
    public void OnValueChange_Sider_amplitude()
    {
        text_sider_amplitude.text = slider_amplitude.value.ToString(); ;
    }

    public Slider slider_milliseconds;
    public Text text_sider_milliseconds;
    public void OnValueChange_Sider_milliseconds()
    {
        text_sider_milliseconds.text = slider_milliseconds.value.ToString(); ;
    }
    AndroidJavaClass jc;
    AndroidJavaObject jo;
    void IniAnroid()
    {
#if UNITY_ANDROID// && !UNITY_EDITOR
        if (jo == null)
        {
            jc =  new AndroidJavaClass("com.plugins.unity.vibrator.VibratorActivity");
            jo = jc.CallStatic<AndroidJavaObject>("getInstance", "Main");
        }
#endif

    }
    public void StartVibrator()
    {
        StopCoroutine("BuyAnimator");
        StartCoroutine("BuyAnimator");
    }

    IEnumerator BuyAnimator()
    {
        long time = (int)slider_milliseconds.value;
        int amplitude = (int)slider_amplitude.value;
        int count = 9;
            while (count > 0)
            {
            StartVibrator(time, amplitude);
            yield return new WaitForSeconds(0.1f);
            }
        StartVibrator(time, amplitude);
    }

    public void StartVibrator(long time, int amplitude)
    {
        //#if UNITY_ANDROID && !UNITY_EDITOR
      
        IniAnroid();
        jo.Call("StartShock", time, amplitude);
        //#endif
    }

}
